#include <stdio.h>
#include <string.h>
#include <dirent.h>
#include <sys/types.h>

void display(const char*);

int main(int argc,char** argv)
{
  display("../");
  return 0;
}

void display(const char* path)
{
  DIR* dir;
  dir = opendir(path);
  if(dir == NULL)
  {
    perror("dir open err");
    return;
  }
  struct dirent* di;
  char filepath[1024];
  static int flag = 0;

  while((di = readdir(dir)))
  {
    
    if(di->d_type == DT_DIR)
    {
      if(!strcmp(di->d_name,"..") || !strcmp(di->d_name,"."))
        continue;
      for(int i = 0;i < flag;i++)
        printf("   ");
      printf("├── ");
      printf("dir name:%s\n",di->d_name);
      snprintf(filepath,1024,"%s/%s",path,di->d_name);
      flag++;
      display(filepath);
      flag--;
    }

    if(di->d_type == DT_REG)
    {
      for(int i = 0;i < flag;i++)
        printf("   ");
      printf("├── ");
      printf("regular name:%s\n",di->d_name);
    }

  }

  closedir(dir);
}
